/**
 * @class   wosh::devices::VlcPlayerBundle
 * @brief   \ref wosh::interfaces::devices::PlayerAudio "Audio player" implementation
 *          based on \c VideoLan \c VLC library, for POSIX systems.
 *
 * @todo [..] DEVICEOUTPUT, PLAYLIST and VOLUME, ALSA STUFF
 *
 * @see     wosh::interfaces::devices::PlayerAudio
 * @see     wosh::devices:PlayerGStreamer
 * @ingroup Devices
 ****************************************************************************
 * @version 0.8.013 $Id: VlcPlayerBundle.h 2887 2010-08-11 08:09:41Z alex $
 * @author  Alessandro Polo
 * @date    Released on 2009-06-04
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/

#ifndef __WOSH_Bundles_Devices_VlcPlayer_H__
 #define __WOSH_Bundles_Devices_VlcPlayer_H__

 #include <core/BundleGeneric.h>

 #include <interfaces/Device.h>
 #include <interfaces/devices/PlayerAudio.h>

 #include "IVlcPlayerListener.h"


namespace wosh {
 namespace devices {

 #define _VlcPlayer_NAME				"VlcPlayer"
 #define _VlcPlayer_VERSION				"0.8.6"

 #define _VlcPlayer_KEY_VlcArguments	"VlcArguments"

class VlcPlayer;
class VlcPlayer086c;
class VlcPlayer099;

class VlcPlayerBundle :	public BundleGeneric,
						public virtual wosh::interfaces::devices::PlayerAudio,
						public virtual IVlcPlayerListener
 {
	WOSH_BUNDLE(wosh::devices::VlcPlayerBundle)
	WOSH_BUNDLE_INTERFACE("wosh::interfaces::devices::PlayerAudio")
	WOSH_BUNDLE_SINGLETON(0,0)

	public:
		/**
		 * @brief   Empty constructor, init bundle and vars, Properties and Methods. May Assign device name
		 * @param device_name [in] output device name, 'default' is the default output for vlc
		 */
		VlcPlayerBundle( const std::string& device_name = "default" );
		/**
		 * @brief   Empty destructor, may (synch) stop bundle and internal threads when still running
		 */
		virtual ~VlcPlayerBundle();


	public:
		WRESULT bundleStart();
		WRESULT bundleStop();
		WRESULT bundleDiagnostic();

		void busMessage( const Message& message, const Bus* source );

//@}
/** @name Device Interface
 * @{
 ******************************************************************************/
	public:
		virtual wosh::interfaces::Device::DEVICE_STATE getDeviceState() const { return this->devState; }
//@}
/** @name PlayerAudio Interface - Playback
 * @{
 ******************************************************************************/
	public:
		virtual WRESULT play( const std::string& file_url );

		virtual WRESULT play();

		virtual WRESULT pause();

		virtual WRESULT stop();

		virtual WRESULT first();

		virtual WRESULT next();

		virtual WRESULT prev();

		virtual WRESULT last();

//@}
/** @name PlayerAudio Interface - PlayList
 * @{
 ******************************************************************************/
	public:
		virtual WRESULT enqueue( const std::string& file_url );

		virtual WRESULT clear();

//@}
/** @name PlayerAudio Interface - Setters
 * @{
 ******************************************************************************/
	public:
		virtual WRESULT setVolume(int newVolume);

		virtual WRESULT setVolumeOffset( int volume_span );
		virtual WRESULT setMute( bool on );

		virtual WRESULT setPosition( float position_rate );
		virtual WRESULT setPositionOffset( float position_rate_offset );

//@}
/** @name PlayerAudio Interface - Getters
 * @{
 ******************************************************************************/
	public:
		virtual int getVolume();
		virtual bool isMuted();

		virtual bool isPlaying();

		virtual int getPlaylistCount();

//@}
/** @name Getters
 * @{
 ******************************************************************************/
	public:

//@}
/** @name Player Events
 * @{
 ******************************************************************************/
 	public:

//@}
/** @name Internal methods
 * @{
 ******************************************************************************/
	protected:
		WRESULT updateInfo();

		/**
		 * @brief   Raise a standard Device event (fact): Create Message and inject in BusDevices (wosh.Bus.Devices)
		 * @param fact [in] the fact (instance) to include in (event) Message, instance will be deleted by Bus
		 */
		void raiseEvent( Fact* fact );

//@}
	protected:
		WRESULT applyingProperty( const std::string& key, const Data& value );

		Response* mmDoPlay( const Request* request );

		Response* mmDoEnqueue( const Request* request );

		Response* mmDoSetVolume( const Request* request );
		Response* mmDoSetMute( const Request* request );

		Response* mmDoSetPosition( const Request* request );

	protected:
		BusConnector BusDevices;		///< register myself & work as Device too
		VlcPlayer086c* playerWorker;	///< real implementation

		wosh::interfaces::Device::DEVICE_STATE devState;		///< current state of device


}; // class def

 }; // namespace devices
}; // namespace wosh

#endif //__WOSH_Bundles_Devices_VlcPlayer_H__
